from fastapi import APIRouter, Query,UploadFile,Request
from tortoise.expressions import Q
from app.controllers.appointment.project import appointment_project_controller
from app.schemas.base import Success, SuccessExtra,Fail
from app.schemas.appointment import *
from app.settings import settings
from dotenv import dotenv_values, set_key

appointment_setting_router = APIRouter()
model_name = "预约基础配置"

@appointment_setting_router.post("/setting", summary=f"更新{model_name}")
async def do_update(
        key: str,
        value,
):
    # 加载现有的 .env 配置
    env_file = 'app/settings/.env'
    env_values = dotenv_values(env_file)

    # 更新或添加新的环境变量
    new_key = key
    new_value = value
    env_values[new_key] = new_value

    # 将更新后的键值对写入到 .env 文件
    with open(env_file, 'w', encoding='utf-8') as f:
        for key, value in env_values.items():
            f.write(f"{key}={value}\n")
    return Success(msg="更新成功")
